<?php
namespace Admin\Controller;

use Common\Controller\CommonController;

class AdminController extends CommonController
{
    public function _initialize()
    {
        $auth = new \Think\Auth();
        //        dump(APP_NAME . '/' . MODULE_NAME . '/' . ACTION_NAME);
        // dump(get_defined_constants(true));
        //查list;
        import('ORG.Util.Operation');
        $operation_obj = new \Org\Util\Operation();
        //$log_list = $operation_obj -> logList(array('member_id' => 2086));
        //记录日志
        //$operation_obj -> checkTableIsExist();//创建日志记录表，如果不存在则新建
        $operation_obj->writeLog(APP_PATH . '' . MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME, '系统后台用户直接操作');
        if (!session('user')) {
            $url = U('Public/index');
            //$this->error('非法访问，正在跳转到登录页面!',U('Public/index'));
            //$this->redirect('Public/index');
            //$this->redirect(PHP_FILE.C('USER_AUTH_GATEWAY'));
            //echo "<script> alert('请重新登录'); </script>";
            echo "<script> top.location.href=" . $url . "; </script>";
            echo "<meta http-equiv='Refresh' content='0;URL=$url'>";
            exit;
        }
        //如果是超级管理员，就有所有的权限。
        $this->update_user_time();
        $this->assign("dbname", C('DB_NAME'));
        if (session('user.account') == 'admin') {
            return true;
        }
        if (!$auth->check(CONTROLLER_NAME . '/' . ACTION_NAME, session('user.id'))) {
            //$this->error('你没有权限');
            //redirect(PHP_FILE . C('USER_AUTH_GATEWAY'));
            $this->error("noaccess:你没有权限！请联系管理员赋予您权限！", 0);
            echo ("你没有权限");
        }
    }
    public function update_user_time()
    {
        $user = M('User');
        $data['id'] = session('user.id');
        $datetime = date("Y-m-d H:i:s", time());
        $data['update_time'] = $datetime;
        $res = $user->save($data);
    }
}
